// DocumentGameModeWebPage.cpp: implementation of the CDocumentGameModeWebPage class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AUSlotsTester.h"
#include "DocumentGameModeWebPage.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDocumentGameModeWebPage::CDocumentGameModeWebPage( const CAUSlotsTesterDoc* pDoc, int nGameMode ) :
	CDocumentWebPage( pDoc ),
	m_nGameMode( nGameMode )
{
}

CDocumentGameModeWebPage::~CDocumentGameModeWebPage()
{
}

void CDocumentGameModeWebPage::GenerateBodyContent()
{
	bool bShowNoSubst = false;
	bool bShowWithSubst = false;

	const CSpinTestResults::CGameModeResults& gmr = GetResults().GetGameModeResults( m_nGameMode );

	for ( int n = 0; n < GetResults().GetNumPayoutTypes(); n++ )
	{
		if ( gmr.m_aPayoutDataNoSubst[ n ].m_nHits )
		{
			bShowNoSubst = true;
		}

		if ( gmr.m_aPayoutDataWithSubst[ n ].m_nHits )
		{
			bShowWithSubst = true;
		}

		if ( bShowNoSubst && bShowWithSubst )
		{
			break;
		}
	}
	
	if ( bShowNoSubst )
	{
		BeginTable( haCenter );
			
			BeginRow();

				BeginColumn();

					BeginBold();

						InsertContent( _T( "Payout Type (Without Substitution)" ) );

					EndBold();

				EndColumn();

				BeginColumn( 20 );

				EndColumn();

				BeginColumn();

					BeginBold();

						InsertContent( _T( "Hits" ) );

					EndBold();

				EndColumn();

				BeginColumn( 20 );

				EndColumn();

				BeginColumn();

					BeginBold();

						InsertContent( _T( "Total Payout" ) );

					EndBold();

				EndColumn();

				BeginColumn( 20 );

				EndColumn();

				BeginColumn();

					BeginBold();

						InsertContent( _T( "Total Payout %" ) );

					EndBold();

				EndColumn();

			EndRow();

			BeginRow();
			
				BeginColumn( 3, 7 );

				EndColumn();

			EndRow();

			for (int n = 0; n < GetResults().GetNumPayoutTypes(); n++ )
			{
				BeginRow();

					BeginColumn();

						InsertContent( GetDocument().GetPayoutTypeName( n ) );

					EndColumn();

					BeginColumn();

					EndColumn();

					BeginColumn( haRight );

						InsertContent( gmr.m_aPayoutDataNoSubst[ n ].m_nHits );

					EndColumn();

					BeginColumn();

					EndColumn();

					BeginColumn( haRight );

						InsertContent( gmr.m_aPayoutDataNoSubst[ n ].m_nTotalPayout );

					EndColumn();

					BeginColumn();

					EndColumn();

					BeginColumn( haRight );

						double d = 0.0;

						if ( GetResults().GetTotalBet() )
						{
							d = (double) gmr.m_aPayoutDataNoSubst[ n ].m_nTotalPayout;

							d /= GetResults().GetTotalBet();

							d *= 100;
						}

						InsertContent( d, 9 );
						InsertContent( _T( "%" ) );

					EndColumn();

				EndRow();
			}

			BeginRow();

				BeginColumn( 3, 7 );

				EndColumn();

			EndRow();

		EndTable();
	}
	else
	{
		BeginParagraph( haCenter );

			InsertContent( _T( "No payout types without substitution were found." ) );

		EndParagraph();
	}

	if ( bShowWithSubst )
	{
		if ( bShowNoSubst )
		{
			InsertContent( _T( "&nbsp;" ) );
		}

		BeginTable( haCenter );
			
			BeginRow();

				BeginColumn();

					BeginBold();

						InsertContent( _T( "Payout Type (With Substitution)" ) );

					EndBold();

				EndColumn();

				BeginColumn( 20 );

				EndColumn();

				BeginColumn();

					BeginBold();

						InsertContent( _T( "Hits" ) );

					EndBold();

				EndColumn();

				BeginColumn( 20 );

				EndColumn();

				BeginColumn();

					BeginBold();

						InsertContent( _T( "Total Payout" ) );

					EndBold();

				EndColumn();

				BeginColumn( 20 );

				EndColumn();

				BeginColumn();

					BeginBold();

						InsertContent( _T( "Total Payout %" ) );

					EndBold();

				EndColumn();

			EndRow();

			BeginRow();
			
				BeginColumn( 3, 7 );

				EndColumn();

			EndRow();

			for (int n = 0; n < GetResults().GetNumPayoutTypes(); n++ )
			{
				BeginRow();

					BeginColumn();

						InsertContent( GetDocument().GetPayoutTypeName( n ) );

					EndColumn();

					BeginColumn();

					EndColumn();

					BeginColumn( haRight );

						InsertContent( gmr.m_aPayoutDataWithSubst[ n ].m_nHits );

					EndColumn();

					BeginColumn();

					EndColumn();

					BeginColumn( haRight );

						InsertContent( gmr.m_aPayoutDataWithSubst[ n ].m_nTotalPayout );

					EndColumn();

					BeginColumn();

					EndColumn();

					BeginColumn( haRight );

						double d = 0.0;

						if ( GetResults().GetTotalBet() )
						{
							d = (double) gmr.m_aPayoutDataWithSubst[ n ].m_nTotalPayout;

							d /= GetResults().GetTotalBet();

							d *= 100;
						}

						InsertContent( d, 9 );
						InsertContent( _T( "%" ) );

					EndColumn();

				EndRow();
			}

			BeginRow();

				BeginColumn( 3, 7 );

				EndColumn();

			EndRow();

		EndTable();
	}
	else
	{
		BeginParagraph( haCenter );

			InsertContent( _T( "No payout types with substitution were found." ) );

		EndParagraph();
	}
}

LPCTSTR CDocumentGameModeWebPage::GetSubTitle() const
{
	return GetDocument().GetGameModeName( m_nGameMode );
}
